﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Corona
{
	/// <summary>
	/// PreviewIcon.xaml 的交互逻辑
	/// </summary>
	public partial class PreviewIcon
	{
		public PreviewIcon()
		{
			this.InitializeComponent();
		}

        public static readonly DependencyProperty PreviewImageProperty = DependencyProperty.Register("PreviewImage", typeof(String), typeof(Icon), new FrameworkPropertyMetadata(PreviewImagePropertyChangeHandler));

        public string Image
        {
            set { SetValue(PreviewImageProperty, value); }
            get { return (string)GetValue(PreviewImageProperty); }
        }

        public static readonly DependencyProperty PreviewTitleProperty = DependencyProperty.Register("PreviewTitle", typeof(String), typeof(Icon), new FrameworkPropertyMetadata(PreviewTitlePropertyChangeHandler));

        public string Title
        {
            set { SetValue(PreviewTitleProperty, value); }
            get { return (string)GetValue(PreviewTitleProperty); }
        }

        private static void PreviewImagePropertyChangeHandler(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            Uri uri = new Uri((source as PreviewIcon).Image);
            BitmapImage bitmapimage = new BitmapImage(uri);
            (source as PreviewIcon).PreviewImage.Source = bitmapimage;
        }

        private static void PreviewTitlePropertyChangeHandler(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            (source as PreviewIcon).PreviewName.Text = (source as Icon).Title;
        }

        //private double offsetX;
        //private double offsetY;
        //private bool IsDragging = false;
        //public Point finaloffsetPos = new Point();
        //private void OnMouseDown(object sender, MouseButtonEventArgs e)
        //{
        //    IsDragging = true;

        //    offsetX = e.GetPosition(sender as Button).X;
        //    offsetY = e.GetPosition(sender as Button).Y;
        //    this.DragShadow.Visibility = Visibility.Visible;
        //}
        //private void OnMouseMove(object sender, MouseEventArgs e)
        //{
        //    if (IsDragging)
        //    {
        //        double currentX = e.GetPosition(ParentCanvas).X;
        //        double currentY = e.GetPosition(ParentCanvas).Y;
        //        Canvas.SetLeft(DragShadow, currentX - offsetX);
        //        Canvas.SetTop(DragShadow, currentY - offsetY);
        //    }
        //}
        //private void OnMouseUp(object sender, MouseButtonEventArgs e)
        //{
        //    Window1 parentWindow = Window.GetWindow(this) as Window1;
        //    IsDragging = false;
        //    this.DragShadow.Visibility = Visibility.Hidden;
        //    finaloffsetPos = e.GetPosition(parentWindow);
        //}
	}
}